﻿<UserControl x:Class="ICSharpCode.Profiler.Controls.QueryView" x:Name="queryView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:ICSharpCode.Profiler.Controls">
	<UserControl.Resources>
		<Style x:Key="ExpandCollapseToggleStyle"
		       TargetType="{x:Type ToggleButton}">
			<Setter Property="Focusable"
			        Value="False"/>
			<Setter Property="Width"
			        Value="19"/>
			<Setter Property="Height"
			        Value="13"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type ToggleButton}">
						<Border Width="19"
						        Height="13"
						        Background="Transparent">
							<Border Width="9"
							        Height="9"
							        BorderThickness="1"
							        BorderBrush="#FF7898B5"
							        CornerRadius="1"
							        SnapsToDevicePixels="true">
								<Border.Background>
									<LinearGradientBrush StartPoint="0,0"
										EndPoint="1,1">
										<LinearGradientBrush.GradientStops>
											<GradientStop Color="White"
											              Offset=".2"/>
											<GradientStop Color="#FFC0B7A6"
											              Offset="1"/>
										</LinearGradientBrush.GradientStops>
									</LinearGradientBrush>
								</Border.Background>
								<Path x:Name="ExpandPath"
								      Margin="1,1,1,1"
								      Fill="Black"
								      Data="M 0 2 L 0 3 L 2 3 L 2 5 L 3 5 L 3 3	L 5 3 L 5 2 L 3 2 L 3 0 L 2 0 L 2 2 Z"/>
							</Border>
						</Border>
						<ControlTemplate.Triggers>
							<Trigger Property="IsChecked"
							         Value="True">
								<Setter Property="Data"
								        TargetName="ExpandPath"
								        Value="M 0 2 L 0 3 L 5 3 L 5 2 Z"/>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
		<Style TargetType="{x:Type ListViewItem}" x:Key="RightAlignedCol">
			<Setter Property="HorizontalContentAlignment"
			        Value="Right" />
		</Style>
		<BooleanToVisibilityConverter x:Key="VisibilityConverter" />
	</UserControl.Resources>
	<Grid>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="75*" MinWidth="260" />
			<ColumnDefinition Width="25*" />
		</Grid.ColumnDefinitions>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition Height="Auto" />
			<RowDefinition Height="1*" />
		</Grid.RowDefinitions>
		<local:TreeListView x:Name="treeView" Grid.Row="2" SelectionMode="Extended">
			<ListView.View>
				<local:CustomGridView>
					<GridViewColumn Header="{Binding Translation.NameColumnText, ElementName=queryView}" Width="240" x:Name="nameColumn">
						<GridViewColumn.CellTemplate>
							<DataTemplate>
								<local:CustomGridViewScrollableCell CurrentScrollPosition="{Binding ElementName=treeView, Path=View.CurrentScrollPosition}">
									<StackPanel Orientation="Horizontal">
										<ToggleButton Visibility="{Binding CheckBoxVisibility}" IsChecked="{Binding IsExpanded}" Margin="{Binding IndentationMargin}" Style="{StaticResource ExpandCollapseToggleStyle}" />
										<Ellipse Width="10" Height="10" HorizontalAlignment="Center" Margin="0,0,0,3" Fill="Red" Visibility="{Binding HotPathIndicatorVisibility}" />
										<TextBlock Text="{Binding Name}" ToolTip="{Binding ToolTip}" />
									</StackPanel>
								</local:CustomGridViewScrollableCell>
							</DataTemplate>
						</GridViewColumn.CellTemplate>
					</GridViewColumn>
					<GridViewColumn Header="{Binding Translation.CallCountColumnText, ElementName=queryView}" Width="60" x:Name="callCountColumn">
						<GridViewColumn.CellTemplate>
							<DataTemplate>
								<TextBlock Text="{Binding CallCount}" HorizontalAlignment="Right" />
							</DataTemplate>
						</GridViewColumn.CellTemplate>
					</GridViewColumn>
					<GridViewColumn Header="{Binding Translation.TimeSpentColumnText, ElementName=queryView}" Width="110" x:Name="timeSpentColumn">
						<GridViewColumn.CellTemplate>
							<DataTemplate>
								<TextBlock HorizontalAlignment="Right" Text="{Binding TimeSpent}" />
							</DataTemplate>
						</GridViewColumn.CellTemplate>
					</GridViewColumn>
					<GridViewColumn Header="{Binding Translation.TimeSpentSelfColumnText, ElementName=queryView}" Width="110" x:Name="timeSpentSelfColumn">
						<GridViewColumn.CellTemplate>
							<DataTemplate>
								<TextBlock HorizontalAlignment="Right" Text="{Binding TimeSpentSelf}" />
							</DataTemplate>
						</GridViewColumn.CellTemplate>
					</GridViewColumn>
					<GridViewColumn Header="{Binding Translation.TimeSpentPerCallColumnText, ElementName=queryView}" Width="110" x:Name="timeSpentPerCallColumn">
						<GridViewColumn.CellTemplate>
							<DataTemplate>
								<TextBlock HorizontalAlignment="Right" Text="{Binding TimeSpentPerCall}" />
							</DataTemplate>
						</GridViewColumn.CellTemplate>
					</GridViewColumn>
					<GridViewColumn Header="{Binding Translation.TimeSpentSelfPerCallColumnText, ElementName=queryView}" Width="110" x:Name="timeSpentSelfPerCallColumn">
						<GridViewColumn.CellTemplate>
							<DataTemplate>
								<TextBlock HorizontalAlignment="Right" Text="{Binding TimeSpentSelfPerCall}" />
							</DataTemplate>
						</GridViewColumn.CellTemplate>
					</GridViewColumn>
					<GridViewColumn Header="{Binding Translation.TimePercentageOfParentColumnText, ElementName=queryView}" Width="80" x:Name="percentColumn">
						<GridViewColumn.CellTemplate>
							<DataTemplate>
								<DockPanel LastChildFill="false">
									<local:PercentBar Value="{Binding TimePercentageOfParent}" Width="25" DockPanel.Dock="Left" />
									<TextBlock Text="{Binding TimePercentageOfParentAsText}"  DockPanel.Dock="Right" />
								</DockPanel>
							</DataTemplate>
						</GridViewColumn.CellTemplate>
					</GridViewColumn>
				</local:CustomGridView>
			</ListView.View>
			<ListView.ItemContainerStyle>
				<Style TargetType="{x:Type ListViewItem}">
					<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
					<Setter Property="HorizontalContentAlignment" Value="Stretch" />
				</Style>
			</ListView.ItemContainerStyle>
		</local:TreeListView>
		<ToolBar Height="26" Grid.Row="0" Grid.ColumnSpan="2">
			<Label Content="{Binding Translation.SearchLabelText, ElementName=queryView}" />
			<TextBox Name="txtSearch" Width="150" KeyDown="txtSearchKeyDown" />
			<CheckBox Content="{Binding Translation.ShowQueryBarText, ElementName=queryView}" IsChecked="{Binding ShowQueryItems}" />
			<Button Content="{Binding Translation.ExpandHotPathSubtreeText, ElementName=queryView}" Name="btnExpandHotPathSubtree" Click="BtnExpandHotPathSubtreeClick" />
		</ToolBar>
		<DockPanel Name="queryPanel" Visibility="{Binding ShowQueryItems, Converter={StaticResource VisibilityConverter}}" Grid.Row="1" Grid.ColumnSpan="2">
			<Button Name="btnExecuteQuery" DockPanel.Dock="Right" Click="btnExecuteQueryClick" Content="{Binding Translation.ExecuteQueryText, ElementName=queryView}" />
			<TextBox Name="txtQuery" TextChanged="txtQueryTextChanged" KeyDown="txtQueryKeyDown" />
		</DockPanel>
		<GridSplitter Width="5" Grid.Column="1" HorizontalAlignment="Left" Grid.Row="2" />
		<Viewbox Name="diagramView" Grid.Column="1" Grid.Row="2" Margin="5,0,0,0">
			<local:RingDiagramControl x:Name="ringDiagram" Translation="{Binding Translation, ElementName=queryView}" SelectedRoot="{Binding SelectedItem, Mode=TwoWay, ElementName=treeView}" />
		</Viewbox>
	</Grid>
</UserControl>
